//
//  CommentViewFrame.m
//  JiaoX
//
//  Created by yinqy on 15/1/9.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "CommentViewFrame.h"
#import "ReComtView.h"




@implementation CommentViewFrame

-(void)setComtInfo:(CommentInfo *)comtInfo{
    _comtInfo = comtInfo;
    //计算头像的frame
    CGFloat headImageX = JXPublicInset;
    CGFloat headImageY = JXPublicInset*1.5;
    CGFloat headImageW = HEADIMAGE_HEIGHT;
    CGFloat headImageH = HEADIMAGE_HEIGHT;
    self.headImageFrame = CGRectMake(headImageX, headImageY, headImageW, headImageH);
    
    //计算回复按钮的frame
    CGFloat replyBtnX = JXScreenW-JXPublicInset-REPLYIMAGE_WIDTH;
    CGFloat replyBtnY = (HEADIMAGE_HEIGHT+JXPublicInset*3-REPLYIMAGE_HEIGHT)*0.5;
    self.replyBtnFrame = CGRectMake(replyBtnX,replyBtnY ,REPLYIMAGE_WIDTH, REPLYIMAGE_HEIGHT);
    
    //计算名称的frame
    CGFloat nameLabelX = CGRectGetMaxX(self.headImageFrame)+JXPublicInset*0.5;
    CGFloat nameLabelY = CGRectGetMinY(self.headImageFrame)+JXPublicInset/4;
    CGFloat nameLabelW = [comtInfo.commentName sizeWithFont:[UIFont systemFontOfSize:NAMELABEL_FONT_SIZE]].width;
    CGFloat nameLabelH = [UIFont systemFontOfSize:NAMELABEL_FONT_SIZE].lineHeight;
    self.nameLabelFrame = CGRectMake(nameLabelX,nameLabelY,nameLabelW,nameLabelH);
    
    //计算时间的frame
    CGFloat timeBtnX = self.nameLabelFrame.origin.x;
    CGFloat timeBtnY = CGRectGetMaxY(self.headImageFrame)-TIMELABEL_FONT_SIZE-JXPublicInset/4;
    CGFloat timeBtnW = JXScreenW-JXPublicInset*2-JXPublicInset-HEADIMAGE_HEIGHT-REPLYIMAGE_WIDTH;
    CGFloat timeBtnH = TIMELABEL_FONT_SIZE;
    self.timeBtnFrame = CGRectMake(timeBtnX, timeBtnY, timeBtnW, timeBtnH);
    
    //计算第1条分割线的frame
    CGFloat splite1FrameX =self.timeBtnFrame.origin.x;
    CGFloat splite1FrameY =CGRectGetMaxY(self.timeBtnFrame)+JXPublicInset;
    CGFloat splite1FrameW =JXScreenW-CGRectGetMinX(self.timeBtnFrame);
    CGFloat splite1FrameH = 0.5;
    self.splite1Frame = CGRectMake(splite1FrameX, splite1FrameY, splite1FrameW,splite1FrameH);

    //计算主评论内容 的frame
    CGFloat contentLabelX = self.timeBtnFrame.origin.x;
    CGFloat contentLabelY = CGRectGetMaxY(self.splite1Frame)+JXPublicInset;
    CGFloat contentLabelW = JXScreenW-CGRectGetMinX(self.timeBtnFrame)-JXPublicInset;
    CGSize size = [comtInfo.commentContent sizeWithFont:[UIFont systemFontOfSize:CONTENTLABEL_FONT_SIZE] constrainedToSize:CGSizeMake(contentLabelW, MAXFLOAT)];
    CGFloat contentLabelH = size.height;
    self.contentLabelFrame = CGRectMake(contentLabelX, contentLabelY, contentLabelW, contentLabelH);
    
    //计算第2条分割线的frame
    CGFloat splite2FrameY = CGRectGetMaxY(self.contentLabelFrame)+JXPublicInset;
    self.splite2Frame = CGRectMake(splite1FrameX, splite2FrameY, splite1FrameW, splite1FrameH);
    
    
    //计算子评论的frame
    if(comtInfo.reComment==nil || comtInfo.reComment.count==0){
        self.reComtViewFrame = CGRectMake(self.timeBtnFrame.origin.x, CGRectGetMaxY(self.splite2Frame), self.splite1Frame.size.width, 0);
    }else{
        self.reComtViewFrame = CGRectMake(self.timeBtnFrame.origin.x, CGRectGetMaxY(self.splite2Frame), self.splite1Frame.size.width, [ReComtView getHeightWithComtArray:comtInfo.reComment width:self.splite1Frame.size.width-JXPublicInset]);
    }
    if(comtInfo.isShowAll==0){
        self.moreBtnViewFrame = CGRectMake(JXScreenW-100-JXPublicInset, CGRectGetMaxY(self.reComtViewFrame), 100, 30);
    }else{
        self.moreBtnViewFrame = CGRectMake(JXScreenW-100-JXPublicInset, CGRectGetMaxY(self.reComtViewFrame), 100, 0);
    }
    self.frame = CGRectMake(0, 0, JXScreenW, CGRectGetMaxY(self.moreBtnViewFrame));
}
@end
